<template>
   <div class="app-container">
      <el-row :gutter="20">
         <!--数据-->
         <el-col>
            <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
               <el-form-item label="机台号" prop="machineId">
                  <el-input
                     v-model="queryParams.machineId"
                     placeholder="请输入机台号"
                     clearable
                     style="width: 240px"
                     @keyup.enter="handleQuery"
                  />
               </el-form-item>
               <el-form-item label="机台名称" prop="machineName">
                  <el-input
                     v-model="queryParams.machineName"
                     placeholder="请输入机台名称"
                     clearable
                     style="width: 240px"
                     @keyup.enter="handleQuery"
                  />
               </el-form-item>
               <el-form-item label="状态" prop="status">
                  <el-select
                     v-model="queryParams.status"
                     placeholder="机台状态"
                     clearable
                     style="width: 240px"
                  >
                     <el-option
                        v-for="dict in game_machine_status"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                     />
                  </el-select>
               </el-form-item>
               <el-form-item label="创建时间" style="width: 308px;">
                  <el-date-picker
                     v-model="dateRange"
                     value-format="YYYY-MM-DD"
                     type="daterange"
                     range-separator="-"
                     start-placeholder="开始日期"
                     end-placeholder="结束日期"
                  ></el-date-picker>
               </el-form-item>
               <el-form-item>
                  <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
               </el-form-item>
            </el-form>

            <el-row :gutter="10" class="mb8">
               <el-col :span="1.5">
                  <el-button
                     type="primary"
                     plain
                     icon="Plus"
                     @click="handleAdd"
                     v-hasPermi="['game:machine:add']"
                  >新增</el-button>
               </el-col>
               <el-col :span="1.5">
                  <el-button
                     type="danger"
                     plain
                     icon="Delete"
                     :disabled="multiple"
                     @click="handleDelete"
                     v-hasPermi="['game:machine:remove']"
                  >删除</el-button>
               </el-col>
               <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
            </el-row>

            <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
               <el-table-column type="selection" width="50" align="center" />
               <el-table-column label="机台号" align="center" key="machineId" prop="machineId" v-if="columns[0].visible" :show-overflow-tooltip="true" />
               <el-table-column label="机台名称" align="center" key="machineName" prop="machineName" v-if="columns[1].visible" :show-overflow-tooltip="true" />
               <el-table-column label="真钱数" align="center" key="CREDITS" prop="CREDITS" v-if="columns[2].visible" :show-overflow-tooltip="true" />
               <el-table-column label="余额" align="center" key="SCORE" prop="SCORE" v-if="columns[3].visible" :show-overflow-tooltip="true" />
               <el-table-column label="概率设置" align="center" key="Probability" prop="Probability" v-if="columns[4].visible" :show-overflow-tooltip="true" >
                  <template #default="scope">
                     <span>{{ getLabelByValue(scope.row.Probability, machine_probability) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="投币比例" align="center" key="tbIndex" prop="tbIndex" v-if="columns[5].visible" :show-overflow-tooltip="true" >
                  <template #default="scope">
                     <span>{{ getLabelByValue(scope.row.tbIndex, machine_tbindex) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="彩票比例" align="center" key="cpIndex" prop="cpIndex" v-if="columns[6].visible" :show-overflow-tooltip="true" >
                  <template #default="scope">
                     <span>{{ getLabelByValue(scope.row.cpIndex, machine_cpindex) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="开分比例" align="center" key="kfIndex" prop="kfIndex" v-if="columns[7].visible" :show-overflow-tooltip="true" >
                  <template #default="scope">
                     <span>{{ getLabelByValue(scope.row.kfIndex, machine_kfindex) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="洗分比例" align="center" key="xfIndex" prop="xfIndex" v-if="columns[8].visible" :show-overflow-tooltip="true" >
                  <template #default="scope">
                     <span>{{ getLabelByValue(scope.row.xfIndex, machine_xfindex) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="进钞比例" align="center" key="jcIndex" prop="jcIndex" v-if="columns[9].visible" :show-overflow-tooltip="true" >
                  <template #default="scope">
                     <span>{{ getLabelByValue(scope.row.jcIndex, machine_jcindex) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="码表比例" align="center" key="mbIndex" prop="mbIndex" v-if="columns[10].visible" :show-overflow-tooltip="true" >
                  <template #default="scope">
                     <span>{{ getLabelByValue(scope.row.mbIndex, machine_mbindex) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="进分上限" align="center" key="jfsxIndex" prop="jfsxIndex" v-if="columns[11].visible" :show-overflow-tooltip="true" >
                  <template #default="scope">
                     <span>{{ getLabelByValue(scope.row.jfsxIndex, machine_jfsxindex) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="系统破台" align="center" key="xtptIndex" prop="xtptIndex" v-if="columns[12].visible" :show-overflow-tooltip="true" >
                  <template #default="scope">
                     <span>{{ getLabelByValue(scope.row.xtptIndex, machine_xtptindex) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="进钞" align="center" key="OutChao" prop="OutChao" v-if="columns[13].visible" :show-overflow-tooltip="true" >
                  <template #default="scope">
                     <span>{{ getLabelByValue(scope.row.OutChao, machine_outchao) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="出银模式" align="center" key="OutSilver" prop="OutSilver" v-if="columns[14].visible" :show-overflow-tooltip="true" >
                  <template #default="scope">
                     <span>{{ getLabelByValue(scope.row.OutSilver, machine_outsilver) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="场地模式" align="center" key="SiteType" prop="SiteType" v-if="columns[15].visible" :show-overflow-tooltip="true" >
                  <template #default="scope">
                     <span>{{ getLabelByValue(scope.row.SiteType, machine_sitetype) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="是否连线" align="center" key="MachineType" prop="MachineType" v-if="columns[16].visible" :show-overflow-tooltip="true" >
                  <template #default="scope">
                     <span>{{ getLabelByValue(scope.row.MachineType, machine_machinetype) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="销售模式" align="center" key="SaleType" prop="SaleType" v-if="columns[17].visible" :show-overflow-tooltip="true" >
                  <template #default="scope">
                     <span>{{ getLabelByValue(scope.row.SaleType, machine_saletype) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="最低押注" align="center" key="MinBetId" prop="MinBetId" v-if="columns[18].visible" :show-overflow-tooltip="true" >
                  <template #default="scope">
                     <span>{{ getLabelByValue(scope.row.MinBetId, machine_min_bet_id) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="状态" align="center" key="status" prop="status" v-if="columns[19].visible">
                  <template #default="scope">
                     <el-switch
                        v-model="scope.row.status"
                        :active-value="1"
                        :inactive-value="0"
                        @change="handleStatusChange(scope.row)"
                     ></el-switch>
                  </template>
               </el-table-column>
               <el-table-column label="在线状态" align="center" key="isWsOnline" prop="isWsOnline" v-if="columns[20].visible" width="90">
                  <template #default="scope">
                     <el-button
                        :type="getLabelByValue(scope.row.isWsOnline, machine_online_type)"
                        :plain="true"
                     >
                        <span>{{ getLabelByValue(scope.row.isWsOnline, machine_online_status) }}</span>
                     </el-button>
                  </template>
               </el-table-column>
               <el-table-column label="备注" align="center" key="remark" prop="remark" v-if="columns[21].visible" width="120" :show-overflow-tooltip="true" />
               <el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[22].visible" width="160">
                  <template #default="scope">
                     <span>{{ parseTime(scope.row.createTime) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="修改时间" align="center" prop="updateTime" v-if="columns[23].visible" width="160">
                  <template #default="scope">
                     <span>{{ parseTime(scope.row.updateTime) }}</span>
                  </template>
               </el-table-column>
               <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">
                  <template #default="scope">
                     <el-tooltip content="修改" placement="top" >
                        <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['game:machine:edit']"></el-button>
                     </el-tooltip>
                     <el-tooltip content="删除" placement="top" ">
                        <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['game:machine:remove']"></el-button>
                     </el-tooltip>
                  </template>
               </el-table-column>
            </el-table>
            <pagination
               v-show="total > 0"
               :total="total"
               v-model:page="queryParams.pageNum"
               v-model:limit="queryParams.pageSize"
               @pagination="getList"
            />
         </el-col>
      </el-row>

      <!-- 添加或修改数据对话框 -->
      <el-dialog :title="title" v-model="open" width="1200px" append-to-body>
         <el-form :model="form" :rules="rules" ref="formRef" label-width="120px">
            <el-row>
               <el-col :span="6">
                  <el-form-item label="机台号" prop="machineId" label-width="90px">
                     <el-input v-model="form.machineId" placeholder="请输入机台号" />
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="机台名称" prop="machineName" label-width="120px">
                     <el-input v-model="form.machineName" placeholder="请输入机台名称" />
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="真钱数" prop="CREDITS" label-width="120px">
                     <el-input v-model="form.CREDITS" placeholder="请输入真钱数" />
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="余额" prop="SCORE" label-width="120px">
                     <el-input v-model="form.SCORE" placeholder="请输入余额" />
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="概率设置" prop="Probability" label-width="120px">
                     <el-select v-model="form.Probability" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_probability"
                           :key="dict.value"
                           :label="dict.label"
                           :value="dict.value"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="投币比例" prop="tbIndex" label-width="120px">
                     <el-select v-model="form.tbIndex" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_tbindex"
                           :key="dict.value"
                           :label="dict.label"
                           :value="dict.value"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="彩票比例" prop="cpIndex" label-width="120px">
                     <el-select v-model="form.cpIndex" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_cpindex"
                           :key="dict.value"
                           :label="dict.label"
                           :value="dict.value"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="开分比例" prop="kfIndex" label-width="120px">
                     <el-select v-model="form.kfIndex" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_kfindex"
                           :key="dict.value"
                           :label="dict.label"
                           :value="dict.value"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="洗分比例" prop="xfIndex" label-width="120px">
                     <el-select v-model="form.xfIndex" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_xfindex"
                           :key="dict.value"
                           :label="dict.label"
                           :value="dict.value"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="进钞比例" prop="jcIndex" label-width="120px">
                     <el-select v-model="form.jcIndex" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_jcindex"
                           :key="dict.value"
                           :label="dict.label"
                           :value="dict.value"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="码表比例" prop="mbIndex" label-width="120px">
                     <el-select v-model="form.mbIndex" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_mbindex"
                           :key="dict.value"
                           :label="dict.label"
                           :value="dict.value"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="进分上限" prop="jfsxIndex" label-width="120px">
                     <el-select v-model="form.jfsxIndex" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_jfsxindex"
                           :key="dict.value"
                           :label="dict.label"
                           :value="dict.value"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="系统破台" prop="xtptIndex" label-width="120px">
                     <el-select v-model="form.xtptIndex" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_xtptindex"
                           :key="dict.value"
                           :label="dict.label"
                           :value="dict.value"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="进钞" prop="OutChao" label-width="120px">
                     <el-select v-model="form.OutChao" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_outchao"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="出银模式" prop="OutSilver" label-width="120px">
                     <el-select v-model="form.OutSilver" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_outsilver"
                           :key="dict.value"
                           :label="dict.label"
                           :value="dict.value"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="场地模式" prop="SiteType" label-width="120px">
                     <el-select v-model="form.SiteType" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_sitetype"
                           :key="dict.value"
                           :label="dict.label"
                           :value="dict.value"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="是否连线" prop="MachineType" label-width="120px">
                     <el-select v-model="form.MachineType" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_machinetype"
                           :key="dict.value"
                           :label="dict.label"
                           :value="dict.value"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="销售模式" prop="SaleType" label-width="120px" label-align="left">
                     <el-input v-model="form.SaleType" placeholder="请输入销售模式0～60" />
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="最低押注" prop="MinBetId" label-width="120px">
                     <el-select v-model="form.MinBetId" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_min_bet_id"
                           :key="dict.value"
                           :label="dict.label"
                           :value="dict.value"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="状态" prop="status" label-width="120px">
                     <template #default="scope">
                        <el-switch
                           v-model="form.status"
                           :active-value="1"
                           :inactive-value="0"
                           @change="handleStatusChangeEdit"
                        ></el-switch>
                        <span>{{ getLabelByValue(form.status, game_machine_status) }}</span>
                     </template>
                  </el-form-item>
               </el-col>
               <el-col :span="6" style="display: none;">
                  <el-form-item label="在线状态" prop="isWsOnline" label-width="120px">
                     <template #default="scope">
                        <el-button
                           :type="getLabelByValue(Number(form.isWsOnline), machine_online_type)"
                           :plain="true"
                        >
                           {{ getLabelByValue(Number(form.isWsOnline), machine_online_status) }}
                        </el-button>
                     </template>
                  </el-form-item>
               </el-col>
            </el-row>
            <el-row>
               <el-col :span="6">
                  <el-form-item label="COM_ID" prop="BillMachine1.COM_ID" label-width="120px">
                     <span>{{ form.BillMachine1.COM_ID }}</span>
                  </el-form-item>
               </el-col>
            </el-row>
            <el-row>
               <el-col :span="6">
                  <el-form-item label="第一种面额" prop="BillMachine1._currency1Index" label-width="170px">
                     <el-select v-model="form.BillMachine1._currency1Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="第二种面额" prop="BillMachine1._currency2Index" label-width="170px">
                     <el-select v-model="form.BillMachine1._currency2Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="第三种面额" prop="BillMachine1._currency3Index" label-width="170px">
                     <el-select v-model="form.BillMachine1._currency3Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="第四种面额" prop="BillMachine1._currency4Index" label-width="170px">
                     <el-select v-model="form.BillMachine1._currency4Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="第五种面额" prop="BillMachine1._currency5Index" label-width="170px">
                     <el-select v-model="form.BillMachine1._currency5Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="第六种面额" prop="BillMachine1._currency6Index" label-width="170px">
                     <el-select v-model="form.BillMachine1._currency6Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="第七种面额" prop="BillMachine1._currency7Index" label-width="170px">
                     <el-select v-model="form.BillMachine1._currency7Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="第八种面额" prop="BillMachine1._currency8Index" label-width="170px">
                     <el-select v-model="form.BillMachine1._currency8Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="面额比例" prop="BillMachine1._currencyRateIndex" label-width="170px">
                     <el-select v-model="form.BillMachine1._currencyRateIndex" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_rate_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="纸钞机类型" prop="BillMachine1._orderMoneyTypeIndex" label-width="170px">
                     <el-select v-model="form.BillMachine1._orderMoneyTypeIndex" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_order_money_type_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
            </el-row>
            <el-row>
               <el-col :span="6">
                  <el-form-item label="COM_ID" prop="BillMachine2.COM_ID" label-width="120px">
                     <span>{{ form.BillMachine2.COM_ID }}</span>
                  </el-form-item>
               </el-col>
            </el-row>
            <el-row>
               <el-col :span="6">
                  <el-form-item label="第一种面额" prop="BillMachine2._currency1Index" label-width="170px">
                     <el-select v-model="form.BillMachine2._currency1Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="第二种面额" prop="BillMachine2._currency2Index" label-width="170px">
                     <el-select v-model="form.BillMachine2._currency2Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="第三种面额" prop="BillMachine2._currency3Index" label-width="170px">
                     <el-select v-model="form.BillMachine2._currency3Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="第四种面额" prop="BillMachine2._currency4Index" label-width="170px">
                     <el-select v-model="form.BillMachine2._currency4Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="第五种面额" prop="BillMachine2._currency5Index" label-width="170px">
                     <el-select v-model="form.BillMachine2._currency5Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="第六种面额" prop="BillMachine2._currency6Index" label-width="170px">
                     <el-select v-model="form.BillMachine2._currency6Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="第七种面额" prop="BillMachine2._currency7Index" label-width="170px">
                     <el-select v-model="form.BillMachine2._currency7Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="第八种面额" prop="BillMachine2._currency8Index" label-width="170px">
                     <el-select v-model="form.BillMachine2._currency8Index" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="面额比例" prop="BillMachine2._currencyRateIndex" label-width="170px">
                     <el-select v-model="form.BillMachine2._currencyRateIndex" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_currency_rate_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="6">
                  <el-form-item label="纸钞机类型" prop="BillMachine2._orderMoneyTypeIndex" label-width="170px">
                     <el-select v-model="form.BillMachine2._orderMoneyTypeIndex" placeholder="请选择">
                        <el-option
                           v-for="dict in machine_billmachine_order_money_type_index"
                           :key="dict.value"
                           :label="dict.label"
                           :value="Number(dict.value)"
                        ></el-option>
                     </el-select>
                  </el-form-item>
               </el-col>
               <el-col :span="24">
                  <el-form-item label="备注" prop="remark">
                     <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
                  </el-form-item>
               </el-col>
            </el-row>
         </el-form>
         <template #footer>
            <div class="dialog-footer">
               <el-button type="primary" @click="submitForm">确 定</el-button>
               <el-button @click="cancel">取 消</el-button>
            </div>
         </template>
      </el-dialog>
   </div>
</template>

<script setup name="Machine">
// import { getToken } from "@/utils/auth";
import { listData, getInfo, addOne, updateOne, removeData, changeStatus } from "@/api/game/machine";
import { getLabelByValue } from "@/utils/index";
const { proxy } = getCurrentInstance();
const { 
   game_machine_status,machine_min_bet_id,
   machine_online_type,machine_online_status,
   machine_probability,machine_tbindex,
   machine_cpindex,machine_kfindex,
   machine_xfindex,machine_jcindex,
   machine_mbindex,machine_jfsxindex,
   machine_xtptindex,machine_outchao,
   machine_outsilver,machine_sitetype,
   machine_machinetype,machine_saletype,
   machine_billmachine_currency_index,
   machine_billmachine_currency_rate_index,
   machine_billmachine_order_money_type_index
} = proxy.useDict(
   "game_machine_status","machine_min_bet_id",
   "machine_online_type","machine_online_status",
   "machine_probability","machine_tbindex",
   "machine_cpindex","machine_kfindex",
   "machine_xfindex","machine_jcindex",
   "machine_mbindex","machine_jfsxindex",
   "machine_xtptindex","machine_outchao",
   "machine_outsilver","machine_sitetype",
   "machine_machinetype","machine_saletype",
   "machine_billmachine_currency_index",
   "machine_billmachine_currency_rate_index",
   "machine_billmachine_order_money_type_index"
);

const dataList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dateRange = ref([]);

// 列显隐信息
const columns = ref([
  { key: 0, label: `机台号`, visible: true },
  { key: 1, label: `机台名称`, visible: true },
  { key: 2, label: `真钱数`, visible: false },
  { key: 3, label: `余额`, visible: true },
  { key: 4, label: `概率设置`, visible: true },
  { key: 5, label: `投币比例`, visible: true },
  { key: 6, label: `彩票比例`, visible: true },
  { key: 7, label: `开分比例`, visible: true },
  { key: 8, label: `洗分比例`, visible: true },
  { key: 9, label: `进钞比例`, visible: false },
  { key: 10, label: `码表比例`, visible: false },
  { key: 11, label: `进分上限`, visible: false },
  { key: 12, label: `系统破台`, visible: false },
  { key: 13, label: `进钞`, visible: false },
  { key: 14, label: `出银模式`, visible: false },
  { key: 15, label: `场地模式`, visible: false },
  { key: 16, label: `是否连线`, visible: false },
  { key: 17, label: `销售模式`, visible: false },
  { key: 18, label: `最低押注`, visible: false},
  { key: 19, label: `状态`, visible: true },
  { key: 20, label: `在线状态`, visible: true },
  { key: 21, label: `备注`, visible: false },
  { key: 22, label: `创建时间`, visible: true },
  { key: 23, label: `修改时间`, visible: true },
]);

const data = reactive({
   form: {},
   queryParams: {
      pageNum: 1,
      pageSize: 10,
      machineId: undefined,
      machineName: undefined,
      status: undefined,
   },
   rules: {
      machineId: [
         { required: true, message: "机台号不能为空", trigger: "blur" },
         { pattern: /^\d+$/, message: "机台号必须为数字", trigger: "blur" },
         { validator: validateIntRange, trigger: "blur" }
      ], 
      machineName: [
         { required: true, message: "机台名称不能为空", trigger: "blur" },
         { min: 1, max: 255, message: "长度必须介于 1 和 255 之间", trigger: "blur" }
      ],
      CREDITS: [
         { required: true, message: "真钱数不能为空", trigger: "blur" },
         { pattern: /^\d+(\.\d{1,2})?$/, message: "真钱数必须为数字", trigger: "blur" },
         { validator: validateDecimalRange, trigger: "blur" }
      ],
      SCORE: [
         { required: true, message: "分数不能为空", trigger: "blur" },
         { pattern: /^\d+(\.\d{1,2})?$/, message: "分数必须为数字", trigger: "blur" },
         { validator: validateDecimalRange, trigger: "blur" }
      ],
      Probability: [{ required: true, message: "概率设置不能为空", trigger: "blur" }],
      tbIndex: [{ required: true, message: "投币比例不能为空", trigger: "blur" }],
      cpIndex: [{ required: true, message: "彩票比例不能为空", trigger: "blur" }],
      kfIndex: [{ required: true, message: "开分比例不能为空", trigger: "blur" }],
      xfIndex: [{ required: true, message: "洗分比例不能为空", trigger: "blur" }],
      jcIndex: [{ required: true, message: "进钞比例不能为空", trigger: "blur" }],
      mbIndex: [{ required: true, message: "码表比例不能为空", trigger: "blur" }],
      jfsxIndex: [{ required: true, message: "进分上限不能为空", trigger: "blur" }],
      xtptIndex: [{ required: true, message: "系统破台不能为空", trigger: "blur" }],
      OutChao: [{ required: true, message: "进钞不能为空", trigger: "blur" }],
      OutSilver: [{ required: true, message: "出银模式不能为空", trigger: "blur" }],
      SiteType: [{ required: true, message: "场地模式不能为空", trigger: "blur" }],
      MachineType: [{ required: true, message: "是否连线不能为空", trigger: "blur" }],
      MinBetId: [{ required: true, message: "最低押注不能为空", trigger: "blur" }],
      SaleType: [
         { required: true, message: "销售模式不能为空", trigger: "blur" },
         { pattern: /^\d+$/, message: "销售模式必须为数字", trigger: "blur" },
         { validator: validateSaleTypeRange, trigger: "blur" }
      ]
   }
});

const { queryParams, form, rules } = toRefs(data);

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
};
/** 删除按钮操作 */
function handleDelete(row) {
   console.log("ids",ids)
  const deleteIds = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除编号为"' + deleteIds + '"的数据项？').then(function () {
    return removeData(deleteIds);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
};
/** 状态修改  */
function handleStatusChange(row) {
  let text = row.status === 0 ? "禁用" : "启用";
  proxy.$modal.confirm('确认要"' + text + '""' + row.machineName + '"吗?').then(function () {
    return changeStatus(row.id, row.status);
  }).then(() => {
    proxy.$modal.msgSuccess(text + "成功");
  }).catch(function () {
    row.status = row.status === 0 ? 1 : 0;
  });
};
/** 编辑界面状态修改  */
function handleStatusChangeEdit(row) {
   // 模拟 API 调用
   return new Promise((resolve) => {
    setTimeout(() => {
      resolve();
    }, 500);
  });
}
/** 选择条数  */
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
  console.log("handleSelectionChange",ids)
};
/** 重置操作表单 */
function reset() {
  form.value = {
    status: 0,
    isWsOnline: 0,
    remark: undefined,
    machineId: undefined,
    machineName: undefined,
    BillMachine1: {
      COM_ID: 1,
      _currency1Index: undefined,
      _currency2Index: undefined,
      _currency3Index: undefined,
      _currency4Index: undefined,
      _currency5Index: undefined,
      _currency6Index: undefined,
      _currency7Index: undefined,
      _currency8Index: undefined,
      _currencyRateIndex: undefined,
      _orderMoneyTypeIndex: undefined,
    },
    BillMachine2: {
      COM_ID: 2,
      _currency1Index: undefined,
      _currency2Index: undefined,
      _currency3Index: undefined,
      _currency4Index: undefined,
      _currency5Index: undefined,
      _currency6Index: undefined,
      _currency7Index: undefined,
      _currency8Index: undefined,
      _currencyRateIndex: undefined,
      _orderMoneyTypeIndex: undefined,
    }
  };
  proxy.resetForm("formRef");
};
/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
};
/** 新增按钮操作 */
function handleAdd() {
  reset();
  title.value = "添加";
  open.value = true;
};
/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  getInfo(row.id).then(response => {
    console.log("handleUpdate",response.data)
    form.value = response.data;
    open.value = true;
    title.value = "修改";
  });
};
/** 提交按钮 */
function submitForm() {
  proxy.$refs["formRef"].validate(valid => {
   console.log("submitForm",form.value)
   console.log("valid",valid)
    if (valid) {
      if (form.value.id != undefined) {
         updateOne(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
         addOne(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
};
/** 验证机台号是否为非零正整数 */
function validateIntRange(rule, value, callback) {
  const intValue = parseInt(value, 10);
  if (isNaN(intValue) || intValue <= 0 || intValue > 2147483647) {
    callback(new Error("机台号必须在1到2147483647之间"));
  } else {
    callback();
  }
}
/** 验证机台号是否为非零正整数 */
function validateSaleTypeRange(rule, value, callback) {
  const intValue = parseInt(value, 10);
  if (isNaN(intValue) || intValue < 0 || intValue > 2147483647) {
    callback(new Error("机台号必须在0到2147483647之间"));
  } else {
    callback();
  }
}
/** 验证是否为Decimal数字 */
function validateDecimalRange(rule, value, callback) {
  const decimalValue = parseFloat(value);
  if (isNaN(decimalValue) || decimalValue < -99999999.99 || decimalValue > 99999999.99) {
    callback(new Error("CREDITS必须在-99999999.99到99999999.99之间"));
  } else {
    callback();
  }
}
/** 查询列表 */
function getList() {
  loading.value = true;
//   console.log("queryParams.value")
//   console.log(queryParams.value)
  listData(proxy.addDateRange(queryParams.value, dateRange.value)).then(res => {
    console.log(res)
    loading.value = false;
    dataList.value = res.rows;
    total.value = res.total;
  });
};

getList();
</script>

<style scoped>
/* 统一所有表单项label的样式 */
.el-dialog .el-form-item :deep(.el-form-item__label) {
  text-align: left !important;
  justify-content: flex-start !important;
  padding-left: 8px !important;
  padding-right: 0px !important;  /* 减小label与输入框的距离 */
  width: 84px !important;
}

/* 如果需要特别处理纸钞机相关的表单项 */
.el-dialog .el-form-item[label*="面额"] :deep(.el-form-item__label),
.el-dialog .el-form-item[label*="纸钞机"] :deep(.el-form-item__label) {
  width: 170px !important;
}

/* 确保label容器不会被压缩 */
.el-dialog .el-form-item :deep(.el-form-item__label-wrap) {
  flex: 0 0 auto;
}

/* 调整列之间的间距 */
.el-dialog .el-col {
  padding-right: 20px !important;  /* 增加列之间的间距 */
}

/* 调整行之间的间距 */
.el-dialog .el-row {
  margin-bottom: 12px !important;  /* 调整行间距 */
}

/* 确保输入框部分能够自适应剩余空间 */
.el-dialog .el-form-item :deep(.el-form-item__content) {
  flex: 1;
  margin-left: 0 !important;
  padding-left: 4px !important;  /* 微调输入框左侧间距 */
}

/* 调整表单项的外边距 */
.el-dialog .el-form-item {
  margin-bottom: 12px !important;  /* 减小表单项底部边距 */
}
</style>
